home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Stacks / Updates⁄New / TEXAS for BMUG / C progs / brwsr.2 ƒ / show_items.2.c < prev   
Encoding:
C/C++ Source or Header  |  1987-11-03  |  4.0 KB  |  156 lines  |  [TEXT/KAHL]

  1. /* functions to show a chosen item from an index key file,etc.
  2.  * 870805-13...  ^z
  3.  */
  4.  
  5. #include <stdio.h>            /* for FILE, getc(), etc. */
  6. #include <strings.h>        /* for strncpy(), etc. */
  7. #include <ctype.h>            /* for isprint(), etc. */
  8. #include <unix.h>            /* for exit(), time(), etc. */
  9. #include <proto.h>            /* for function prototypes */
  10. #include "brwsr.h"            /* for various definitions */
  11. #include "brwsr.proto.h"    /* for my function prototypes */
  12.  
  13.  
  14. /* function to show whatever the current item is, in whatever level
  15.  * the user is at the moment.... basically, it just routes the
  16.  * request to whichever is the appropriate agent to take care of
  17.  * it, for INDEX, CONTEXT, or TEXT levels....
  18.  */
  19.  
  20. void show_current_item ()
  21.   {
  22.     extern int level;
  23.     extern FILE *doc_file;
  24.     
  25.     if (doc_file == NULL)
  26.       {
  27.         beep ();
  28.         printf ("No file open!\n");
  29.         return;
  30.       }
  31.     
  32.     if (level == INDEX)
  33.         show_current_index_item ();
  34.     else if (level == CONTEXT)
  35.         show_current_context_item ();
  36.     else
  37.         show_current_text_item ();
  38.   }
  39.  
  40.  
  41. /* function to show the current INDEX item (count of occurrences followed
  42.  * by the indexed word itself) ... send copy to notes file, if open....
  43.  */
  44.  
  45. void show_current_index_item ()
  46.   {
  47.     extern KEY_REC this_rec, prev_rec;
  48.     extern long current_item[], subset_rec_count;
  49.     extern FILE *notes_file;
  50.     extern char *subset;
  51.     long count_subset_recs ();
  52.     void get_key_rec ();
  53.  
  54.     get_key_rec (&prev_rec, current_item[INDEX] - 1);
  55.     get_key_rec (&this_rec, current_item[INDEX]);
  56.     
  57.     if (subset == NULL)
  58.       {
  59.         printf ("%6ld %.28s\n", this_rec.ccount - prev_rec.ccount,
  60.                     this_rec.kkey);
  61.         if (notes_file != NULL)
  62.             fprintf (notes_file, "%6ld %.28s\n",
  63.                     this_rec.ccount - prev_rec.ccount, this_rec.kkey);
  64.       }
  65.     else
  66.       {
  67.           subset_rec_count = count_subset_recs (&this_rec, &prev_rec);
  68.         printf ("%6ld/%-6ld %.28s\n", subset_rec_count,
  69.                     this_rec.ccount - prev_rec.ccount, this_rec.kkey);
  70.         if (notes_file != NULL)
  71.         fprintf (notes_file, "%6ld/%-6ld %.28s\n", subset_rec_count,
  72.                     this_rec.ccount - prev_rec.ccount, this_rec.kkey);
  73.       }
  74.   }
  75.  
  76.  
  77. /* function to show the current CONTEXT item, a line in the form of a
  78.  * key-word-in-context (KWIC) display with the indexed term in the'
  79.  * middle ... the line is filtered so that the presence of tabs, <cr>'s,
  80.  * or other nasty control characters won't cause any problems... 
  81.  * a little testing is needed to take care of end-effects, so that 
  82.  * nothing happens for context lines near either end of the document
  83.  * file ... finally, send a copy to the notes file, if open....
  84.  */
  85.  
  86. void show_current_context_item ()
  87.   {
  88.     register int n, m;
  89.     register long p;
  90.     char buf[CONTEXT_LINE_LENGTH + 1];
  91.     extern long current_item[];
  92.     extern FILE *doc_file;
  93.     
  94.     p = current_item[TEXT] - CONTEXT_OFFSET;
  95.     n = 0;
  96.     if (p < 0)
  97.       {
  98.         for ( ; n < -p; ++n)
  99.             buf[n] = ' ';
  100.         p = 0;
  101.       }
  102.     if (fseek (doc_file, p, 0) != 0)
  103.           {
  104.             beep ();
  105.             printf ("Error in fseek() getting a context line to show!\n");
  106.             return;
  107.           }
  108.     if ((m = fread (buf + n, sizeof (char), CONTEXT_LINE_LENGTH - n,
  109.                         doc_file)) == 0)
  110.           {
  111.             beep ();
  112.             printf ("Error in fread() getting a context line to show!\n");
  113.             return;
  114.           }
  115.     n += m;
  116.     for ( ; n < CONTEXT_LINE_LENGTH; ++n)
  117.         buf[n] = ' ';
  118.     for (n = 0; n < CONTEXT_LINE_LENGTH; ++n)
  119.         if (! isprint (buf[n] & 0xFF))
  120.             buf[n] = ' ';
  121.     buf[CONTEXT_LINE_LENGTH] = '\0';
  122.     printf ("%s\n", buf);
  123.     if (notes_file != NULL)
  124.         fprintf (notes_file, "%s\n", buf);
  125.   }
  126.  
  127.  
  128. /* function to show the current TEXT item, a line from the document file
  129.  * itself ... copy to notes file also, if so desired....
  130.  */
  131.  
  132. void show_current_text_item ()
  133.   {
  134.     char buf[STRLEN + 1];
  135.     extern long current_item[];
  136.     extern FILE *doc_file;
  137.     
  138.     if (fseek (doc_file, current_item[TEXT], 0) != 0)
  139.           {
  140.             beep ();
  141.             printf ("Error in fseek() getting a text line to show!\n");
  142.             return;
  143.           }
  144.     if (fgets (buf, STRLEN, doc_file) == NULL)
  145.           {
  146.             beep ();
  147.             printf ("Error in fgets() getting a text line to show!\n");
  148.             return;
  149.           }
  150.     printf ("%s", buf);
  151.     if (notes_file != NULL)
  152.             fprintf (notes_file, "%s", buf);
  153.   }
  154.  
  155.  
  156.